import datetime


def format_datetime(condition):
    current_time = datetime.datetime.now()

    if (current_time - condition).days == 0:
        return condition.strftime("%H:%M")
    if (current_time - condition).days == 1:
        return "昨天"
    if (current_time - condition).days == 2:
        return "前天"
    if 2 < (current_time - condition).days < 365:
        return condition.strftime("%m-%d")
    if (current_time - condition).days > 365:
        return condition.strftime("%Y-%m-%d")


def format_datetime_group(condition):
    """
    用于列表时间归类
    :param condition:
    :return:
    """
    current_time = datetime.datetime.now()

    if (current_time - condition).days == 0:
        return condition.strftime("")
    elif (current_time - condition).days == 1:
        return "昨天"
    elif (current_time - condition).days == 2:
        return "前天"
    elif 2 < (current_time - condition).days < 365:
        return condition.strftime("%m-%d")
    elif (current_time - condition).days > 365:
        return condition.strftime("%Y-%m-%d")
